<!--瀑布图-->
<template>
  <div
    class="chartcontainer"
    v-if="iffresh"
  >
    <div :style="{'margin-bottom':'10px'}" v-if="title">{{title}}</div>
    <!-- :judge-width="true" -->
    <ve-waterfall
      :data="blockdata"
      width="100%"
      height="100%"
      ref="mychart"
      :theme="theme"
      :judge-width="true"
      :after-config="afterConfig"
      :grid="grid"
    >
    </ve-waterfall>
  </div>
</template>

<script>
import VeWaterFall from "v-charts/lib/waterfall.common";

export default {
  name: "block1",
  props: [
    "chartData",
    "changesizewidth",
    "changesizeheight",
    "theme",
    "timer",
    "title",
    "searchid",
    "chartid",
    "field",
    "isShowLegend"//用户判断是否显示图注
  ],
  data() {
    this.chartSettings = {
    };
    this.grid = {
      left: 60,
      top: 40,
      right: 100,
      bottom: 120
    }
    return {
      intervaltime: this.timer,
      blockdata: this.chartData,
      iffresh: true
    };

  },

  components: { VeWaterFall },
  created() { },
  mounted() { },
  destroyed() { },
  methods: {
    afterConfig(options) {
      if (!this.isShowLegend) {
        options.legend = {
          data: []
        }
      }
      options.yAxis.axisLabel = {
        textStyle: {
          fontSize: 12  //刻度大小
        }
      }
      options.xAxis.axisLabel = {
        interval: 0,
        textStyle: {
          fontSize: 12  //刻度大小
        },
        formatter: function (val) {
          if (val.length < 10) {
            return val.split("").join("\n");
          }
          var strs = val.split(""); //字符串数组
          var str = "";
          for (var i = 0, s; (s = strs[i++]);) {
            //遍历字符串数组
            str += s;
            if (!(i % 2)) str += "\n"; //按需要求余
          }
          return str;
        } //横轴
      };
      return options;
    }
  },
  watch: {
    changesizewidth(oldvalue, newvalue) {
      this.$refs.mychart.echarts.resize();
    },

    changesizeheight(oldvalue, newvalue) {
      this.$refs.mychart.echarts.resize();
    },
    chartData(oldvalue, newvalue) {
      this.blockdata = oldvalue;
      ;
    }
  }
};
</script>
<style scoped lang="scss">
.chartcontainer {
  width: 100%;
  height: 100%;
}
</style>

